package com.yupi.yuaiagent.rag;

import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class LoveAppVectorStoreConfig {

    @Resource
    private LoveAppDocumentReader loveAppDocumentReader;


    /**
     * 加载markdown 文件。然后 自动转换成向量数据 ，存储到内存中的某一个向量数据库中
     * @param dashscopeEmbeddingModel
     * @return
     */
    @Bean
    public VectorStore loveAppVectorStore(EmbeddingModel dashscopeEmbeddingModel) {

        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(dashscopeEmbeddingModel)
                .build();

        List<Document> documents = loveAppDocumentReader.readerMarkdowns("file:D:/markdown/*.md");
        simpleVectorStore.add(documents);

        return simpleVectorStore;

    }


}
